DS18B20 1-wire temperatuur sensor

  • VDD = 3v3
  • signal pin = GPIO4
  • 4.7 KOhm pull-up on signal

Raspbery Pi installation + detecting the device ID:

> sudo modprobe w1-gpio
> sudo modprobe w1-therm
> cd /sys/bus/w1/devices/
> ls

note: watch out with the Raspberry Pi 2 (because of DeviceTree config):
"dtoverlay=w1-gpio" needs to be added to /boot/config.txt
http://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314


In [ ]:
# Read sensor info in file format
temp_file = open("/sys/bus/w1/devices/28-011465166dff/w1_slave")
temp_text = temp_file.read() 
temp_file.close()

# The temperature can be found on the second line in the 10th column
second_line = temp_text.split("\n")[1] 
temperature_text = second_line.split(" ")[9]

# The first two characters are "t=", so we'll drop those and convert the rest to a number.
temperature = float(temperature_text[2:]) 
# Convert from millidegrees to degrees.
temperature = temperature / 1000 
print("Measured temperature: {}".format(temperature))

In [ ]: